﻿#include "RenderPch.h"

#include "RenderFacade.h"
#include "Light.h"


HRESULT RenderFacade::BeginDefaultRender()
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->BeginScene();
	}

	return S_FALSE;
}

HRESULT RenderFacade::EndDefaultRender()
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->EndScene();
	}
	return S_FALSE;
}

HRESULT RenderFacade::Present( CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
	}
	return S_FALSE;
}

HRESULT RenderFacade::Clear( DWORD Count, CONST D3DRECT * pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->Clear( Count, pRects, Flags, Color, Z, Stencil );
	}

	return S_FALSE;
}

HRESULT RenderFacade::CreateTexture( UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle );
	}
	return S_FALSE;
}

HRESULT RenderFacade::CreateVertexBuffer( UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->CreateVertexBuffer( Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle );
	}
	return S_FALSE;
}

HRESULT RenderFacade::CreateIndexBuffer( UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->CreateIndexBuffer( Length, Usage, Format, Pool, ppIndexBuffer, pSharedHandle );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetFVF( DWORD fvf )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetFVF( fvf );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetFVF( DWORD* pfvf )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetFVF( pfvf );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetTexture( DWORD Sampler, IDirect3DBaseTexture9* pTexture )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetTexture( Sampler, pTexture );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetTexture( DWORD Stage, IDirect3DBaseTexture9** ppTexture )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetTexture( Stage, ppTexture );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetTextureStageState( Stage, Type, Value );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetTextureStageState( Stage, Type, pValue );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetRenderState( D3DRENDERSTATETYPE State, DWORD Value )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetRenderState( State, Value );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetRenderState( D3DRENDERSTATETYPE State, DWORD* pValue )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetRenderState( State, pValue );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetSamplerState( Sampler, Type, Value );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetSamplerState( Sampler, Type, pValue );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetTransform( D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetTransform( State, pMatrix );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetTransform( D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetTransform( State, pMatrix );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetStreamSource( UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetStreamSource( StreamNumber, pStreamData, OffsetInBytes, Stride );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetStreamSource( UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* pOffsetInBytes, UINT* pStride )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetStreamSource( StreamNumber, ppStreamData, pOffsetInBytes, pStride );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetIndices( IDirect3DIndexBuffer9* pIndexData )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetIndices( pIndexData );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetIndices( IDirect3DIndexBuffer9** pIndexData )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetIndices( pIndexData );
	}

	return S_FALSE;
}

HRESULT RenderFacade::SetViewport( CONST D3DVIEWPORT9* pViewport )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetViewport( pViewport );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetViewport( D3DVIEWPORT9* pViewport )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetViewport( pViewport );
	}
	return S_FALSE;
}
HRESULT RenderFacade::SetMaterial( CONST D3DMATERIAL9 * pMaterial )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetMaterial( pMaterial );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetMaterial( D3DMATERIAL9 * pMaterial )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetMaterial( pMaterial );
	}
	return S_FALSE;
}

HRESULT RenderFacade::SetLight( const DWORD& uIndex, const CLight* pLight )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->SetLight( uIndex, pLight );
	}
	return S_FALSE;
}

HRESULT RenderFacade::GetLight( const DWORD& uIndex, CLight* pLight )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->GetLight( uIndex, pLight );
	}
	return S_FALSE;
}

HRESULT RenderFacade::LightEnable( const DWORD& LightIndex, const BOOL& bEnable )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->LightEnable( LightIndex, bEnable );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT TriangleCount )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->DrawPrimitive( PrimitiveType, StartVertex, TriangleCount );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DrawPrimitiveUP( D3DPRIMITIVETYPE PrimitiveType, UINT TriangleCount, CONST void* pVertexArray, UINT VertexArraySize )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->DrawPrimitiveUP( PrimitiveType, TriangleCount, pVertexArray, VertexArraySize );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DrawIndexedPrimitive( D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT TriangleCount )
{
	if( m_lpd3dDevice )
	{
		return m_lpd3dDevice->DrawIndexedPrimitive( Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, TriangleCount );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DXCreateTexture( UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, LPDIRECT3DTEXTURE9* ppTexture )
{
	if( m_lpd3dDevice )
	{
		return D3DXCreateTexture( m_lpd3dDevice, Width, Height, MipLevels, Usage, Format, Pool, ppTexture );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DXCreateTextureFromFile( LPCTSTR pSrcFile, LPDIRECT3DTEXTURE9 * ppTexture )
{
	if( m_lpd3dDevice )
	{
		return D3DXCreateTextureFromFile( m_lpd3dDevice, pSrcFile, ppTexture );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DXCreateFont( INT Height, UINT Width, UINT Weight, UINT MipLevels, BOOL Italic, DWORD CharSet, DWORD OutputPrecision, DWORD Quality, DWORD PitchAndFamily, LPCTSTR pFacename, LPD3DXFONT* ppFont )
{
	if( m_lpd3dDevice )
	{
		return D3DXCreateFont( m_lpd3dDevice, Height, Width, Weight, MipLevels, Italic, CharSet, OutputPrecision, Quality, PitchAndFamily, pFacename, ppFont );
	}
	return S_FALSE;
}

HRESULT RenderFacade::DXCreateFontIndirect( CONST D3DXFONT_DESC* pDesc, LPD3DXFONT* ppFont )
{
	if( m_lpd3dDevice )
	{
		return D3DXCreateFontIndirect( m_lpd3dDevice, pDesc, ppFont );
	}
	return S_FALSE;
}


